#include "stm32f10x.h"                  // Device header


void Timer_Init(void)
{
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//开启时钟
	
	TIM_InternalClockConfig(TIM2);//使用内部时钟
	
	TIM_TimeBaseInitTypeDef TIM_InitStructure;//定义定时器结构体
	TIM_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;//滤波频率
	TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数
	TIM_InitStructure.TIM_Period = 10000-1;//自动重装值
	TIM_InitStructure.TIM_Prescaler = 7200-1;//预分频值
	TIM_InitStructure.TIM_RepetitionCounter = 0;//高级定时器才用
	TIM_TimeBaseInit(TIM2,&TIM_InitStructure);//初始化定时器
	TIM_ClearFlag(TIM2,TIM_FLAG_Update);//清除首次中断
	
	TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);//开启中断
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
	
	NVIC_InitTypeDef NVIC_InitStrucyure;
	NVIC_InitStrucyure.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitStrucyure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStrucyure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStrucyure.NVIC_IRQChannelSubPriority = 1;
	
	NVIC_Init(&NVIC_InitStrucyure);
	
	TIM_Cmd(TIM2,ENABLE);
}








